package cn.emall.controller;

import cn.emall.pojo.EasyUIDataGridResult;
import cn.emall.pojo.TbItem;
import cn.emall.utils.EmallResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.emall.service.ItemService;

@Controller
public class ItemController {

	@Autowired
	private ItemService itemService;

	@RequestMapping("/item/{itemId}")
	@ResponseBody
	public TbItem getItemById(@PathVariable Long itemId) {
		TbItem tbItem = itemService.getItemById(itemId);
		return tbItem;
	}

	@RequestMapping(value = "/item/list")
	@ResponseBody
	public EasyUIDataGridResult getResult(int page,int rows){
		EasyUIDataGridResult easyUIDataGridResult = itemService.getItemList(page,rows);
		return easyUIDataGridResult;
	}

	/**
	 * 商品添加功能
	 */
	@RequestMapping(value = "/item/save",method = RequestMethod.POST)
	@ResponseBody
	public EmallResult insertItem(TbItem tbItem,String desc){
		EmallResult emallResult = itemService.insertItem(tbItem,desc);
		return emallResult;
	}
}
